#include <Dynamics/ExtForce/gravity_cpu.h>

namespace PhysLeo
{
    
template<typename T>
void GravityCpu<T>::allocateResource(SimData<T>& simData)
{
    gravity_acceleration_ = simData.gravity_acceleration_;
    ptr_mass_ = simData.ptr_mass_;
}

template<typename T>
void GravityCpu<T>::addGravityForce(std::shared_ptr<BufferData<glm::tvec3<T>>> force)
{
    auto force_ptr = force->ptrCpu();
    auto mass_ptr = ptr_mass_->ptrCpu();
    const int vert_num = ptr_mass_->size();

    for(auto vert_id=0;vert_id<vert_num;++vert_id)
    {
        force_ptr[vert_id] += mass_ptr[vert_id] * gravity_acceleration_;
    }
}

template class GravityCpu<float>;
template class GravityCpu<double>;

}